<template>
  <div>
    <el-dialog
      title="编辑厂商"
      :visible.sync="dialogVisible"
      width="500px"
      :before-close="closeAddDialog"
    >
      <el-form
        :model="editData"
        :rules="rules"
        ref="refeditData"
        label-width="100px"
      >
        <el-form-item size="small" label="联系人姓名" prop="username">
          <el-input
            clearable
            v-model.trim="editData.username"
            placeholder="请输入"
            maxlength="20"
            style="width: 360px"
          ></el-input>
        </el-form-item>
        <el-form-item size="small" label="联系人手机" prop="mobile">
          <el-input
            clearable
            oninput="value=value.replace(/[^\d]/g,'')"
            @blur="editData.mobile = $event.target.value"
            v-model.trim="editData.mobile"
            placeholder="请输入"
            maxlength="11"
            style="width: 360px"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeAddDialog" class="cancel-button">取 消</el-button>
        <el-button size="small" @click="addSubmit" v-preventReClick="1000" class="confirm-button"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { reqManufacturerEdit } from "@api/api";
import rulesMixin from "../mixins/rules.js";
export default {
  props: {
    editData: {
      type: Object,
      default: () => {},
    },
  },
  mixins: [rulesMixin],
  data() {
    return {
      dialogVisible: false,
    };
  },
  methods: {
    // 点击编辑
    addSubmit() {
      this.$refs.refeditData.validate(async (valid) => {
        if (!valid) return ;
        let params = {
          id: this.editData.id,
          username: this.editData.username,
          mobile: this.editData.mobile,
        };
        const res = await reqManufacturerEdit(params);
        if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
        this.$modal.notifySuccess("编辑厂商成功");
        this.closeAddDialog();
        this.$parent.getDataList(); //更新厂商列表
      });
    },
    // 点击关闭弹框
    closeAddDialog() {
      this.$refs.refeditData.resetFields();
      this.dialogVisible = false;
      this.$emit("clearEditData");
    },
  },
};
</script>

<style lang="less" scoped>
</style>
